﻿using MediatR;
using W.Purchase.API.Application.Command.FinanceTypeCommand;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.FinanceTypeCommandHandler
{
    public class FinanceTypeDeleteCommandHandler:IRequestHandler<FinanceTypeDeleteCommand,int>
    {
        private readonly IFinanceTypesRepository _financeTypesRepository;
        public FinanceTypeDeleteCommandHandler(IFinanceTypesRepository financeTypesRepository)
        {
            _financeTypesRepository = financeTypesRepository;
        }

        public async Task<int> Handle(FinanceTypeDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = await _financeTypesRepository.GetAllAsaync();
            var plist = list.Where(c=>c.FinanceTypeId==request.FinanceTypeId).FirstOrDefault();
            if (plist != null)
            {
                plist.IsDelete = true;
            }
            return await _financeTypesRepository.Update(plist);
        }
    }
}
